package com.ai.module.chat.config.interceptor;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;

import java.time.LocalDateTime;
import java.util.Locale;
import java.util.UUID;

/**
 * @author: MrHe
 * @create: 2023-09-02 10:42
 * @description:
 **/
@Configuration
public class GptMybatisHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject,"uuid", String.class, UUID.randomUUID().toString().toLowerCase(Locale.ROOT));
        this.strictInsertFill(metaObject,"created_time", LocalDateTime.class,LocalDateTime.now());
        this.strictInsertFill(metaObject,"updated_time", LocalDateTime.class,LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject,"updated_time", LocalDateTime.class,LocalDateTime.now());
    }

}
